﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using SDF.Core;
using SDF.Web.Framework.Mvc;
using FluentValidation.Attributes;
using SDF.Plugin.Misc.SAPAdapter.Validators;
using SDF.Web.Framework;

namespace SDF.Plugin.Misc.SAPAdapter.Models
{
    [Validator(typeof(SAPClientModelValidator))]
    public class SAPClientModel: BaseSDFEntityModel
    {
        [SDFResourceDisplayName("Plugins.Misc.SAPAdapter.SAPInstance.Client")]
        public string Client { get; set; }

        [SDFResourceDisplayName("Plugins.Misc.SAPAdapter.SAPInstance.CodeName")]
        public string CodeName { get; set; }

        [SDFResourceDisplayName("Plugins.Misc.SAPAdapter.SAPInstance.Name")]
        public string Name { get; set; }

        [SDFResourceDisplayName("Plugins.Misc.SAPAdapter.SAPInstance.Delete")]
        public bool Delete { get; set; }

        [SDFResourceDisplayName("Plugins.Misc.SAPAdapter.SAPInstance.CreateTime")]
        public DateTime CreateTime { get; set; }

        [SDFResourceDisplayName("Plugins.Misc.SAPAdapter.SAPInstance.User")]
        public string User { get; set; }

        [SDFResourceDisplayName("Plugins.Misc.SAPAdapter.SAPInstance.Password")]
        public string Password { get; set; }

        [SDFResourceDisplayName("Plugins.Misc.SAPAdapter.SAPInstance.SystemNumber")]
        public string SystemNumber { get; set; }

        [SDFResourceDisplayName("Plugins.Misc.SAPAdapter.SAPInstance.Language")]
        public string Language { get; set; }

        [SDFResourceDisplayName("Plugins.Misc.SAPAdapter.SAPInstance.ApplicationServer")]
        public string ApplicationServer { get; set; }

        [SDFResourceDisplayName("Plugins.Misc.SAPAdapter.SAPInstance.MessageServerHost")]
        public string MessageServerHost { get; set; }

        [SDFResourceDisplayName("Plugins.Misc.SAPAdapter.SAPInstance.LogonGroup")]
        public string LogonGroup { get; set; }

        [SDFResourceDisplayName("Plugins.Misc.SAPAdapter.SAPInstance.IsGroupLogon")]
        public bool IsGroupLogon
        {
            get
            {
                return ApplicationServer.IsNullOrEmpty() &&
                    (MessageServerHost.IsNullOrEmpty() == false && LogonGroup.IsNullOrEmpty() == false);
            }
        }

        [SDFResourceDisplayName("Plugins.Misc.SAPAdapter.SAPInstance.ServerDisplay")]
        public string ServerDisplay
        {
            get
            {
                return IsGroupLogon ?
                    $"{MessageServerHost}:{LogonGroup}" :
                    ApplicationServer;
            }
        }

        [SDFResourceDisplayName("Plugins.Misc.SAPAdapter.SAPInstance.SystemID")]
        public string SystemID { get; set; }

        [SDFResourceDisplayName("Plugins.Misc.SAPAdapter.SAPInstance.SAPRouter")]
        public string SAPRouter { get; set; }
        
    }
}